package tasks.leetcode.算法通关;

import java.util.HashMap;
import java.util.HashSet;
import java.util.function.BiConsumer;

public class GreedyCoinChange {
    public static void main(String[] args) {
        int coins[] = new int[]{25, 10, 5, 1};
        int amount = 63;

        HashMap<Integer, Integer> map = new HashMap<>();
        map = coinChanges(map, coins, amount);

        map.forEach(new BiConsumer<Integer, Integer>() {
            @Override
            public void accept(Integer coinValue, Integer number) {
                System.out.println("是用了硬币值是" + coinValue+"的硬币有" + number + "个");
            }
        });
    }

    private static HashMap<Integer, Integer> coinChanges(HashMap<Integer, Integer> map, int[] coins, int amount) {
        for (int coin : coins) {
            int numbers = amount / coin;
            map.put(coin, numbers);
            amount = amount - coin * numbers;
        }
        return map;
    }


}
